package com.example.zhihuhelpapp.utils;

import android.app.Application;
import android.content.Context;

import org.litepal.LitePal;

public class CoreLib {
    private static Application mContext;

    public static void init(Application application) {
        mContext = application;
        LitePal.initialize(mContext);
    }

    public static Context getContext() {
        return mContext;
    }

    public static boolean isNeedUrl(String url) {
        return isAnswer(url) || isQuestion(url);
    }

    public static boolean isAnswer(String url) {
        return url.startsWith(CoreConstant.rootUrl) && url.contains("answer");
    }

    public static boolean isQuestion(String url) {
        return url.startsWith(CoreConstant.rootUrl) && url.contains("question");
    }

    public static String getQuestionOrAnswerId(String url) {
        int lastIndex = url.lastIndexOf("/");
        int isHasParams = url.indexOf("?");
        LogUtils.i("isHasParams: "+isHasParams);
        if (isHasParams >=0) {
            return url.substring(lastIndex + 1,isHasParams);
        }else{
            return url.substring(lastIndex + 1);
        }
    }
}
